package com.mp.approvalreq.util;


import com.mp.approvalreq.exception.SpecialLogicException;
import com.plusmoney.exception.RpcServerLogicalException;
import com.plusmoney.exception.enums.RespCodeDesc;
import org.slf4j.Logger;

import java.sql.SQLException;

public class ErrorUtils {
    public static Throwable throwError(Throwable e, Logger logger) {
        logger.error(e.getMessage(), e);

        return throwError(e);
    }


    public static Throwable throwError(Throwable e) {
        if (SQLException.class.isAssignableFrom(e.getClass())) {
            return new RpcServerLogicalException(RespCodeDesc.DATABASE_ERROR);
        } else if (RpcServerLogicalException.class.isAssignableFrom(e.getClass())) {
            return e;
        } else if (e instanceof SpecialLogicException) {
            return new RpcServerLogicalException("002", "提交成功");
        } else {
            SpecialLogicException.class.isAssignableFrom(e.getClass());
            return new RpcServerLogicalException(RespCodeDesc.SYSTEM_ERROR);
        }
    }

}
